#include "mex.h"
#include <math.h>

static void mcprice(double p[], double ou[],double W[], int r, int c)
{
        int i,j;
        double dt=0.5/5000;

        for (j=0; j<c; j++)
		{
			p[j*r]=0;

			for (i=0; i<r-1; i++)
            {
              //  p[j*r+i+1]=p[j*r+i]+ou[j*r+i]*ou[j*r+i]*dt+ou[j*r+i]*W[j*(r-1)+i]*sqrt(dt);
                p[j*r+i+1]=p[j*r+i]+ou[j*r+i]*W[j*(r-1)+i]*sqrt(dt);
            }
		}


}

//  static void variation(long Npaths)
//  {
//      int i;
//      for (i=0,i<Npaths,i++)
//
//  }


void mexFunction(int nlhs,mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
        double *p, *ou, *W;
        int row,column;
        double a, b, m, sigma0;
        row=mxGetM(prhs[0]); column=mxGetN(prhs[0]);
        
        plhs[0]=mxCreateDoubleMatrix(row,column,mxREAL);        
        p=mxGetPr(plhs[0]);
        
        ou=mxGetPr(prhs[0]);
        W =mxGetPr(prhs[1]);

        mcprice(p,ou,W,row, column);


}
